import * as Type from "./type";
import * as request from "@/common/request";
import { CommonResult } from "@/common/request/result.type";
const newError = () => new Error("请求失败");

/**
 * 任务大厅
 *
 */
export async function getTaskAcceptablePageApi(
  GetTaskAcceptablePageForm: Type.TaskDto
): Promise<CommonResult<Type.TaskAll>> {
  try {
    const { data } = await request.post<Type.TaskAll>(
      "task/showAcceptablePage",
      GetTaskAcceptablePageForm
    );
    return data;
  } catch {
    throw newError();
  }
}

/**
 * id查询任务
 *
 */
export async function getTaskByIdApi(id: number): Promise<CommonResult<Type.TaskInfo>> {
  try {
    const { data } = await request.get<Type.TaskInfo>("task/" + id);
    return data;
  } catch {
    throw newError();
  }
}
/**
 * id查询任务(含发布者)
 *
 */
export async function getTaskUserByIdApi(id: number): Promise<CommonResult<Type.TaskUserInfo>> {
  try {
    const { data } = await request.get<Type.TaskUserInfo>("task/taskUser/" + id);
    return data;
  } catch {
    throw newError();
  }
}
